<?php 
$weekarr = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
$week = $weekarr[date("w")];
?>
<script type="text/javascript">
    function readURL2(input,id) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
                $('#'+id).val(input.value);
            };
            reader.readAsDataURL(input.files[0]);
        }
    }
</script>
<div id="company" class="indexcontentdiv">
    <div class="positiondiv">
        <table>
            <tr>
                <td class="td-left">
                    <img src="<?=base_url()?>resource/img/home_ico.png" width="21" height="17">
                    Data Entry > <a href="<?=base_url()?>index/company">Comany</a> > Company Detail
                </td>
                <td class="td-right">
                    <img src="<?=base_url()?>resource/img/menu2.png" width="27" height="24">Today is <?=$week?>,<?=date('M d,Y')?>
                </td>
            </tr>
        </table>
    </div>
    <div class="detail-div">
        <div class="detail-menu">
            <div class="active1 detail-active" id="menu1">Company Information</div>
            <div class="active2 single-menu" id="menu2">Attachment List</div>
            <div style="width:0px;"></div>
        </div>
        <div class="input-div">
            <?php echo form_open_multipart('index/update_company'); ?>
            <input type="hidden" name="id" value="<?=$company['id']?>" />
            <table>
                <tr><td></td><td><span class="err"><?=validation_errors();?><?php if(isset($error)){echo $error;}?></span></td></tr>
                <tr><td colspan="2"><h3>.Company</h3></td></tr>
                <tr><td class="nametd">SN:</td><td><input type="text" name="sn" value="<?=$company['sn']?>"/></td></tr>
                <tr><td class="nametd">UEN:</td><td><input type="text" name="uen" value="<?=$company['uen']?>"/></td></tr>
                <tr><td class="nametd">Company Name:</td><td><input type="text" name="name" value="<?=$company['name']?>"/><span class="err">*</span></td></tr>
                <tr>
                    <td class="nametd">Industry:</td>
                    <td>
                        <select name="industry" id="industry" style="width:140px;">
                            <option value="0">-Industry-
                            <?php foreach ($industry as $key => $value) {?>
                                <option value="<?=$value['id']?>"><?=$value['name']?>
                            <?php }?>
                        </select>
                    </td>
                </tr>
                <tr><td class="nametd">Contact Person:</td><td><input type="text" name="person" value="<?=$company['person']?>"/></td></tr>
                <tr><td class="nametd">Position:</td><td><input type="text" name="position" value="<?=$company['position']?>"/></td></tr>
                <tr><td class="nametd">Contact No:</td><td><input type="text" name="number" value="<?=$company['number']?>"/></td></tr>
                <tr><td class="nametd">Email:</td><td><input type="text" name="email" value="<?=$company['email']?>"/></td></tr>
                <tr><td class="nametd">Contact Status:</td>
                    <td>
                        <select name="status" id="status">
                            <option value="0">-Select-
                            <option value="1">Positive
                            <option value="2">Neutral
                            <option value="3">Hostile
                        </select>
                    </td>
                </tr>
                <tr><td class="nametd">Comments:</td>
                    <td>
                        <textarea name="comment"><?=$company['comment']?></textarea>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="submit" value="Save"/>
                    </td>
                </tr>
            </table>
            <?php echo form_close(); ?>
        </div>
        <div class="list-div" style="display:none;">
            <table class="list-table">
                <tr>
                    <th width="200">Company Name</th>
                    <!--<th width="200">Attachment Name</th>-->
                    <th>Attachment</th>
                    <th width="100"></th>
                </tr>
                <?php foreach ($attachments as $key => $value) {?>
                <tr>
                    <td><?=$company['name']?></td>
                    <!--<td><?=$value['title']?></td>-->
                    <td><a href="<?=base_url("index/downfile").'/'.$value['path']?>" target="_blank"><?=$value['path']?></a></td>
                    <td>
                        <a href="<?=base_url('index/deleteattachment').'/'.$value['id'].'/'.$company['id'] ?>" class="buttona">
                            <img src="<?=base_url()?>resource/img/delete.png"/>delete
                        </a>
                    </td>
                </tr>
                <?php }?>
                <tr>
                    <td></td>
                    <td colspan="2" class="relative" style="text-align:left;">
                        <form action="<?=base_url('index/newattachment/'.$company['id'].'/9')?>" method="post" enctype="multipart/form-data" onsubmit="return checkform()">
                            <input type="text" placeholder="attachment path" id="attachmentpath" style="width:540px;margin-left:30px;margin-right:30px;"/>
                            <img src="<?=base_url()?>resource/img/upload.png" width="25" height="29" style="position:absolute;left:545px;top:3px;" />
                            <input type="file" id="path" class="inputfile" name="path" size="20" onchange="readURL2(this,'attachmentpath');" 
                                   style="position:absolute;width:25px;height:29px;left:545px;top:3px;cursor:pointer;opacity:0;filter:alpha(opacity=0);"/>
    <!--                        <select name="type" style="width:100px;height:30px;border-radius:5px;border:1px solid #c9c9c9;">
                                <option value="0">Normal
                                <?php
                                    $flag = false;
                                    foreach ($attachments as $key => $value) {
                                        if($value['type'] == 1){
                                            $flag = true;
                                        }
                                    }
                                    if(!$flag){?>
                                        <option value="1">Confirmation Letter
                                <?php }?>
                            </select>-->
                            <input type="hidden" name="type" value="0" />
                            <input type="hidden" name="title" value="WokerNormal" />
                            <input type="submit" style="position:absolute;width:29px;height:29px;background:#ffffff url(<?=base_url()?>resource/img/save.png) no-repeat;
                                   background-repeat:round;right:40px;top:4px;cursor:pointer;border:none;" value=""/>
                        </form>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<script>
var companyid = '<?=$company['id']?>';
$("#status").val("<?=$company['status']?>");
$("input[name='name']").focus(function(){
}).blur(function(){
    if($(this).val() == ''){
        alert("Name can not be empty！");
    }
});
$("#industry").val("<?=$company['industry']?>");
$("#saleser").val("<?=$company['saleser']?>");

//$(function(){
//if($.session.get('companydetailid'+companyid) != undefined){
//    var id = $.session.get('companydetailid'+companyid);
//    $("#"+id).removeClass("single-menu").addClass("detail-active");
//    
//    if(id == "menu1"){
//        $(".input-div").css("display","block");
//        $(".list-div").css("display","none");
//    }else{
//        $(".input-div").css("display","none");
//        $(".list-div").css("display","block");
//    }
//}else{
//    $.session.set('companydetailid'+companyid,"menu1");
//    $("#menu1").removeClass("single-menu").addClass("detail-active");
//}   
//});


cutmenu();
function cutmenu(){
    $(".single-menu").click(function(){
        $(".detail-active").removeClass("detail-active").addClass("single-menu");
        $(this).removeClass("single-menu").addClass("detail-active");
        var id = $(this).attr("id");
        if(id == "menu1"){
            $(".input-div").css("display","block");
            $(".list-div").css("display","none");
        }else{
            $(".input-div").css("display","none");
            $(".list-div").css("display","block");
        }
        cutmenu();
        $.session.set('companydetailid'+companyid,id);
    });
}
</script>
　